package com.c4.controller;

import com.c4.domain.PageBean;
import com.c4.domain.Result;
import com.c4.domain.deviceStatus;
import com.c4.service.IdeviceStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/device")
public class deviceStatusController {

    @Autowired
    private IdeviceStatusService ideviceStatusService;

    //设备详情分页展示
    @GetMapping
    public Result<PageBean<deviceStatus>> list(Integer pageNum,Integer pageSize){
        PageBean<deviceStatus> pd =ideviceStatusService.list(pageNum,pageSize);
        return Result.success(pd);
    }

    //id找设备
    @GetMapping("/detail")
    public Result<deviceStatus> detail(Integer id){
        deviceStatus d = ideviceStatusService.detail(id);
        return Result.success(d);
    }

    //设备全部显示
    @GetMapping("/all")
    public Result<List<deviceStatus>> listAll(){
        List<deviceStatus> ss = ideviceStatusService.listAll();
        return Result.success(ss);
    }

    //添加设备
    @PostMapping
    public Result add(@RequestBody @Validated(deviceStatus.Add.class) deviceStatus deviceStatus){
        ideviceStatusService.add(deviceStatus);
        return Result.success();
    }

    //删除设备
    @DeleteMapping
    public Result<deviceStatus> delete(Integer id){
        ideviceStatusService.delete(id);
        return Result.success();
    }

    //故障设备分页显示
    @GetMapping("/warn")
    public Result<PageBean<deviceStatus>> listWarn(Integer pageNum,Integer pageSize){
        PageBean<deviceStatus> lw =ideviceStatusService.listWarn(pageNum,pageSize);
        return Result.success(lw);
    }

    //正常设备显示
    @GetMapping("/normal")
    public Result<List<deviceStatus>> listNormal(){
        List<deviceStatus> ln = ideviceStatusService.listAllNormal();
        return Result.success(ln);
    }

    //修改设备故障状态
    @PutMapping("/warn")
    public Result warnUpdate(@RequestBody deviceStatus deviceStatus){
        ideviceStatusService.warnUpdate(deviceStatus);
        return Result.success();
    }

    //设备故障已解决分页显示
    @GetMapping("/stra")
    public Result<PageBean<deviceStatus>> listStra(Integer pageNum,Integer pageSize){
        PageBean<deviceStatus> ls = ideviceStatusService.listStra(pageNum,pageSize);
        return Result.success(ls);
    }

    //故障设备处理策略
    @PutMapping("/stra")
    public Result straUpdate(@RequestBody deviceStatus deviceStatus){
        ideviceStatusService.straUpdate(deviceStatus);
        return Result.success();
    }

}
